package com.shelpe.services.sinbad.entity.mongo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.sinbad.entity.jpa.User;

import lombok.Data;

@Data
@Document(collection = "keyword_handler_error_logs")
public class KeywordPriceErrorLog {
	@Id
	private String id;
	@Indexed
	private long userID;
	@Indexed
	private Date executeTime;
	private String errorCode;

	private List<KeywordWord> words;
	
	private String res;

	public void from(User user) {
		this.userID = user.getUserID();

		this.executeTime = new Date();
		this.id = this.userID + "_" + this.executeTime.getTime();
	}

	public void addWord(KeywordWord word) {
		if (this.words == null) {
			this.words = new ArrayList<KeywordWord>();
		}
		this.words.add(word);
	}

	@Data
	public static class KeywordWord {
		private long keywordID;
		private String word;
		private int matchScope;
		private int maxPrice;
		private int isDefaultPrice;
		private int maxMobilePrice;
		private int mobileIsDefaultPrice;
	}
}
